/*
 * Copyright 1999-2021 Alibaba Group Holding Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.aliyun.odps.mma.server.ui;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.aliyun.odps.mma.server.JobScheduler;
import com.aliyun.odps.mma.server.job.JobManager;
import com.aliyun.odps.mma.server.ui.config.ConfigTab;
import com.aliyun.odps.mma.server.ui.jobs.JobsTab;
import com.aliyun.odps.mma.server.ui.tasks.TasksTab;
import com.aliyun.odps.mma.server.ui.utils.JettyUtils;

public class MmaUi extends WebUi {
  private static final Logger LOG = LogManager.getLogger(MmaUi.class);

  private static final String STATIC_RESOURCE_DIR = "com/aliyun/odps/mma/server/ui/static";

  public MmaUi(
      String basePath,
      JobManager jobManager,
      JobScheduler jobScheduler) {
    super(basePath);
    JobsTab jobsTab = new JobsTab(this, "jobs", jobManager);
    TasksTab tasksTab = new TasksTab(this, "tasks", jobScheduler);
    ConfigTab configTab = new ConfigTab(this, "config");
    attachTab(jobsTab);
    attachTab(tasksTab);
    attachTab(configTab);
    addStaticHandler(STATIC_RESOURCE_DIR, "/static");
    attachHandler(JettyUtils.createRedirectHandler("/", "/jobs/", basePath));
  }
}
